home *** CD-ROM | disk | FTP | other *** search
- NAME
- expr - evaluate arguments as an expression
-
- SYNTAX
- expr [-v] [arg] ...
-
- DESCRIPTION
- The arguments are taken as an expression. After evaluation,
- the result is written on the standard output.
-
- If the -v option is present the result is printed in decimal, octal
- and hexadecimal form, and the unsigned equilavence in long, int,
- and char is also output if the result is negative.
-
- If arguments are missing on the command line, then arguments are
- taken from the standard input. Each line is processed separately.
-
- The operators and keywords are listed below. The list is in
- order of increasing precedence, with equal precedence operators
- grouped.
-
- expr : expr
- yields the first expr if it is not zero, otherwise
- yields the second expr. Note that the ':' is the colon.
-
- expr & expr
- yields the first expr if neither expr is zero,
- otherwise yields '0'.
-
- expr relop expr
- where relop is one of LT LE NE EQ GE GT, yields '1' if the
- indicated comparison is true, '0' if false.
-
- expr + expr
- expr - expr
- addition or subtraction of the arguments.
-
- expr * expr
- expr / expr
- expr % expr
- multiplication, division, or remainder of the arguments.
-
- ! expr
- - expr
- unary logic negation (!) or numeric negation (-) of the argument.
-
- ( expr )
- parentheses for grouping.
-
- #
- #n
- recalls the previous answers for n = 0-9 and # is #0 (last result).
- This is only useful if the arguments are taken from the standard
- input.
-
- EXAMPLE
- expr "45 * 32 / 2"
- expr 200+20-45 & 64 / 65
- expr 5 gt $LASTNUM
-
- DIAGNOSTICS
- Expr returns the following exit codes:
- 0 if the expression is neither null nor '0',
- 1 if the expression is null or '0',
- 2 for invalid expressions.
-
- SEE ALSO
- test, hoc
-
- RESTRICTIONS
- The result is a long integer and all the arguments have to be integers
- or characters ('...'). On the command line, the character quotes ( ' )
- have to be escaped (\') so they won't be removed. The multiplication
- sign (*) has to be enclosed in quotes on the command line so file names
- are not generated.